package io.gitee.wminyu.day03.Sort;

public class BinarySearch {
    public static void main(String[] args) {
        int array[] = {1,5,9,7,13,14,57,201};
        int mid;
        int low = 0, height = array.length-1;
        int target = 15;
        while (low<=height){
            mid = (low+height)/2;
            if (target<array[mid]){
                height =mid-1;
            }else if(target>array[mid]){
                low = mid+1;
            }else {
                System.out.println("找到数字："+array[mid]+"在第"+(mid+1)+"个位置");
//                break;
                return;
            }
        }
        System.out.println("该数组没有找到"+target);
//        if (low>height){
//            System.out.println("该数组没有找到"+target);
//        }
    }
}
